class_name StatusManage extends Node

########################## 有限状态机模型
var status_map : Dictionary
var status_msg : Dictionary
var status:int
var status_before :int 

func change_status(next_status:int):
	if next_status != status:
		# 状态变更
		status_before = status
		status = next_status
		
		# 变幻状态
		stop_status_node(status_before)
		start_status_node(status)
		
		# 打印状态变更
		var msg :String
		msg = get_status_msg(status_before)
		#print("%s has stop" % msg);

		msg = get_status_msg(status)
		#print("%s start" % msg)

func set_default_status(set_status:int):
	status_before =  set_status
	status =  set_status
	start_status_node(set_status)
	
func add_status_node(status, node, info ):
	status_map[status] = node
	status_msg[status] = info
	node.manage_node = self

func get_status_node(local_status:int):
	return status_map.get(local_status)
	
func stop_status_node(local_status:int):
	var node = get_status_node(local_status)
	node.stop_node();
	
func start_status_node(local_status:int):
	var node = get_status_node(local_status)
	node.start_node()
	
# 打印当前的状态
func print_play_status():
	if status_before == status:
		return
	var msg = get_status_msg(status)
	print(msg)
	
func get_status()->int:
	return status
	
func get_status_msg(status):
	return status_msg.get(status)
